//
//  PBRegistViewController.m
//  PBHomeDemo
//
//  Created by Playboy on 2017/12/19.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "PBRegistViewController.h"
#import "PBSurePasswordController.h"

@interface PBRegistViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@end

@implementation PBRegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self configure];
}
- (void)configure {
    [self configureView];
    [self configureData];
}
- (void)configureView {
    [self.phoneTextField addTarget:self action:@selector(phoneTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
- (void)configureData {
    
}

- (void)phoneTextFieldDidChange:(UITextField *)textField {
    if (textField.text.length > 11) {
        textField.text = [textField.text substringToIndex:11];
    }
}

- (IBAction)buttonClick:(UIButton *)sender {
    if (self.phoneTextField.text.length == 0) {
        [self showHint:@"手机号不能为空"];
        return;
    }
    NSDictionary *param = @{@"mobile":self.phoneTextField.text};
    [self showHud];
    [TMNetwork requestPostWithParam:param url:@"/user/sendVercode" callback:^(TMBaseReqModel *model) {
        [self hideHud];
        if (model.code == 200) {
                PBSurePasswordController *vc = [[PBSurePasswordController alloc] init];
                vc.phone = self.phoneTextField.text;
                [self.navigationController pushViewController:vc animated:YES];
        }else {
            [self showHint:model.message];
        }
    }];
    
    
    
    
}

#pragma mark - super
- (void)resetNavigationBarItems {
    [super resetNavigationBarItems];
    self.title = @"手机号注册";
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
